package com.apexedu.identity.service.impl;

import com.apexedu.framework.service.impl.AbstractBaseServiceSupport;
import com.apexedu.framework.util.DBUtil;
import com.apexedu.framework.util.Pager;
import com.apexedu.identity.action.IdMenuButtonAction;
import com.apexedu.identity.entity.TSysMenu;
import com.apexedu.identity.service.IdMenuButtonService;
import com.apexedu.sys.entity.ApplicationEnum;
import com.apexedu.util.StringUtil;

import java.util.List;

/**
 * 菜单按钮配置
 *
 * @author Linyang datetime 2011-6-7
 */
public class IdMenuButtonServiceImpl extends AbstractBaseServiceSupport implements IdMenuButtonService {

    public List<?> list(Object myaction, Pager pager) throws Exception {
        IdMenuButtonAction action = (IdMenuButtonAction) myaction;
        String upmenuid = action.getParameter("upmenuid");
        action.setParameter("upmenuid", upmenuid);
        action.setParameter("appname", getMenuName(upmenuid));
        String sql = "select * from " +
                "(select t.menuid,t.menuname,t.state,aa.zdmc as srctype,t.bizcode,t.menupath," +
                "case when t.depth=3 then nvl(t.ordernum,1)*100500 else nvl(tt.ordernum,1)*100000+nvl(t.ordernum,1) end as ono  from t_sys_menu t " +
                "inner join t_sys_menu tt on t.upmenuid=tt.menuid left join t_sys_code aa on aa.zdbm=t.srctype and aa.zdlb='zylx'" +
                " where t.belongtoapp=? ) where state = '1'" +
                " order by ono desc ";
        return DBUtil.queryAllBeanList(sql, TSysMenu.class, upmenuid);
    }

    /**
     * 根据业务id获取菜单名
     *
     * @param appid 菜单id
     * @return 业务名
     * @throws Exception
     */
    private String getMenuName(String appid) throws Exception {
        String hql = "select appname from TAccessAppReg where appid=?";
        String appname = (String) getBaseDao().findFieldValue(hql, appid);
        return appname;
    }

    public void load(Object myaction) throws Exception {
    }

    public void openCreate(Object arg0) throws Exception {
    }

    public boolean remove(Object arg0) throws Exception {
        return false;
    }

    public void saveOrUpdate(Object arg0) throws Exception {
    }
}
